from pydantic import BaseModel
from typing import Tuple, Type
from pydantic_settings import (
    BaseSettings,
    PydanticBaseSettingsSource,
    SettingsConfigDict,
    TomlConfigSettingsSource,
)


class JWTSettings(BaseModel):
    algorithm:str 
    access_token_expire_minutes:int
    secret_key:str


class RedisSettings(BaseModel):
    name: str 
    host: str #="192.168.2.172"
    port: int #=6379
    password: str #="foobared"
    brokerdb: int #=0
    backenddb: int

    
class AgentSettings(BaseModel):
    host: str 
    port: int 


class TokenAgeingSettings(BaseModel):
    days: float 
    seconds: float
    minutes: float
    hours: float
    weeks: float

    
class PostGreSqlSettings(BaseModel):
    host: str 
    port: int 
    password: str 
    user: str 
    database: str


class Settings(BaseSettings):
    jwt_params: JWTSettings
    agent: AgentSettings
    token_ageing: TokenAgeingSettings
    redis_connection: RedisSettings
    postgresql_connection: PostGreSqlSettings
    model_config = SettingsConfigDict(
        env_file_encoding='utf-8',
        toml_file='/data/fengyy/project/FlaskBlueprint/app/config.toml')
    
    @classmethod
    def settings_customise_sources(
        cls,
        settings_cls: Type[BaseSettings],
        init_settings: PydanticBaseSettingsSource,
        env_settings: PydanticBaseSettingsSource,
        dotenv_settings: PydanticBaseSettingsSource,
        file_secret_settings: PydanticBaseSettingsSource,
    ) -> Tuple[PydanticBaseSettingsSource, ...]:
        return (TomlConfigSettingsSource(settings_cls),)




